class MyArray{
  constructor(ary){
    this.ary = new Array(ary),
    this.size = 0
  }
  insert(index, element){
    if(index<0 || index>this.size) {
      throw new Error('超出数组实际元素范围')
    }
    if(this.size >= this.ary.length) {
      this.resize()
    }
    for(let i = this.size-1; i >= index; i--){
      this.ary[i+1] = this.ary[i]
    }
    this.ary[index] =element
    this.size++
  }
  resize(){
    let newAry = this.ary.concat(new Array(this.ary.length))
    this.ary = newAry
  }
  delete(index){
    if(index<0 || index>this.size) {
      throw new Error('超出数组实际元素范围')
    }
    let deleteElement = this.ary[index]
    for(let i = index; i < this.size-1; i++) {
      this.ary[i] = this.ary[i+1]
    }
    this.size--
    return deleteElement
  }
  output(){
    console.log(this.ary)
    for(let i=0; i<this.size; i++){
      console.log(this.ary[i])
    }
  }
}

let myArray = new MyArray(4)
myArray.insert(0,3)
myArray.insert(1,7)
myArray.insert(2,9)
myArray.insert(3,5)
myArray.insert(1,6)
myArray.insert(5,8)
myArray.delete(3)
myArray.output()